#include<allegro.h>


int main ()

{

BITMAP *buffer;
BITMAP *bg;
BITMAP *img;
BITMAP *img1;
BITMAP *img2;
BITMAP *img3;

int x=0;
int y=300;

int x1=0;
int y1=150;

int x2=300;
int y2=300;

int x3;
int y3;

int direction = 1;

int b =0;
int life = 1;


/* General initialization function */
 allegro_init();

   if (install_keyboard() == -1)
  {
 allegro_message("Error! %s", allegro_error);
  return -1;
  }

 set_color_depth(16);

   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0) != 0) 
  {
 set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); /* here’s the command for text mode */
 allegro_message("Unable to initialize video mode!\n%s\n", allegro_error);
   return 1;
  }

buffer=create_bitmap(800,600);

 bg=load_bitmap("bar.bmp",NULL);
 img=load_bitmap("derriere.bmp",NULL);
 img1=load_bitmap("alex0.bmp",NULL);

   if(bg==NULL && img==NULL && img1 == NULL)
  {
 allegro_message("rien");
 allegro_exit();
  }



  while(!key[KEY_ESC])

  {

 clear_bitmap(buffer);


   if (key[KEY_RIGHT])
  {
    x++;
  }

   if (key[KEY_LEFT])
 {
  x--;
 }

   if (key[KEY_SPACE])
                                
 {
 x2 = x;
 y2 = y;
 b = 1;
 }
 
   if  ((x1  <= SCREEN_W - img1->w) && direction == 1)
 {
 x1++;

   if((x1  >= SCREEN_W - img1->w))
  {
		direction =0;	
  }

  }

    else
  {
	
 x1--;

   if((x1  <= 100))
   {
 direction =1;	
   }
   
   }
 

 draw_sprite(buffer,bg,0,0);
 draw_sprite(buffer,img,x,y);

   if(life == 1)

 draw_sprite(buffer,img1,x1,y1);
   if(b==1)

  {
   if(y2>=50)
  {

 img2=load_bitmap("bombe0.bmp",NULL);
 draw_sprite(buffer,img2,x2,y2);
 y2--;
  }
   else
  {

 clear_bitmap(img2);
//b=0;

 img3=load_bitmap("bombe1.bmp",NULL);
  
 
  //usleep(9000);
	y2--;

   if(y2<=20)
  {

 clear_bitmap(img3);
 x3 = 50;
 y3 = 500;
  } 

   else
  {
 x3 = x2;
 y3 = 50;

 draw_sprite(buffer,img3,x3,y3);
  }
  }

  }

   if(x1<= (x3+140) && (x1+140)>x3 && y1>= y3 && y1<=(y3+150))

 {

 life = 0;

 clear_bitmap(img1);
  }


 blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);

  }
 

  readkey();

  destroy_bitmap(buffer);
   return 0;
}


END_OF_MAIN();
